package com.springboot.file.util.easyexcel.exception;

import java.io.Serial;

/**
 * 事务处理异常，用于表示在事务处理过程中发生的错误
 */
public class TransactionProcessingException extends RuntimeException {
    @Serial
    private static final long serialVersionUID = 1L;

    public TransactionProcessingException(String message) {
        super(message);
    }

    public TransactionProcessingException(String message, Throwable cause) {
        super(message, cause);
    }

    /**
     * 获取最原始的异常原因
     * @return 原始异常对象
     */
    public Throwable getOriginalCause() {
        Throwable rootCause = this.getCause();
        // 递归查找最原始的异常
        while (rootCause != null && rootCause.getCause() != null) {
            rootCause = rootCause.getCause();
        }
        return rootCause;
    }
}
